let arr = [6,8,9,1,4,2,2]

// 这里length-1代表除去最后一项
for(let i=0; i<arr.length-1; i++) {
    for(let j=0; j<arr.length-1-i; j++) {
        let temp = 0;
        if (arr[j]>arr[j+1]) {
            temp = arr[j]
            arr[j] = arr[j+1]
            arr[j+1] = temp
        }
    }
}
console.log(arr)